package com.example.demo.permissionFilter;

import com.example.demo.Permission;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @DESCRIPTION:
 * @AUTOOR: Lee
 * @DATE: 2022年09月18日 2:04
 */
@Aspect
@Component
public class permissionFilter {

    @Pointcut("execution(public * com.example.demo.controller.*.*(..)) & @annotation(com.example.demo.Permission)")
    public void pointCut() {

    }

    /**
     * 前置通知，目标方法调用前被调用
     */
    @Before("pointCut()")
    public void beforeAdvice(JoinPoint joinPoint)  {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();

        Permission permission = method.getDeclaredAnnotation(Permission.class);
        if (permission != null) {

        }
    }

}
